<?php
class Bootstrap extends Zend_Application_Bootstrap_Bootstrap
{
	protected function _initAutoloaded()
	{
		$autoLoader = Zend_Loader_Autoloader::getInstance();
		$autoLoader->registerNamespace(
			array(
				'Custom_Controller_Plugin_',
				'Custom_Controller_Payment_'
			)
		);
		
		$loader = new Zend_Application_Module_Autoloader(
			array(
			  'namespace' => '',
			  'basePath' => APPLICATION_PATH
			)
		);
	}
	
	protected function _initDoctype()
	{
		$this->bootstrap('view');
		$view = $this->getResource('view');
		$options = $this->getOptions();
		$viewOptions = $options['resources']['view'];
		
		$view->headMeta()->appendHttpEquiv('Content-Type', 'text/html;charset='.$viewOptions['encoding']);
		$view->headTitle($viewOptions['title']);
		$view->doctype('XHTML1_STRICT');
	}
	
	protected function _initView()
	{
		$options = $this->getOptions();
		$viewOptions = $options['resources']['view'];
		$view = new Zend_View($viewOptions);
		
		if(!empty($viewOptions['params'])) {
			foreach($viewOptions['params'] as $key => $value)
				$view->$key = $value;
		}
		
		$viewRenderer = Zend_Controller_Action_HelperBroker::getStaticHelper(
			'ViewRenderer'		
		);
		
		$viewRenderer->setView($view);
		
		// 注册自定义试图助手
		$view->addHelperPath(
			$viewOptions['params']['manager']['helperPath'], 
			$viewOptions['params']['manager']['helperPathPrefix']
		);
		
		$view->addHelperPath(
			$viewOptions['params']['web']['helperPath'],
			$viewOptions['params']['web']['helperPathPrefix']
		);
		
		return $view;
	}
	
	protected function _initDB()
	{
		$options = $this->getOption('resources');
		$options = $options['db'];
		
		$db = Zend_Db::factory($options['adapter'], $options['params']);
		$db->query($options['driver_options']);
		
		Zend_Db_Table::setDefaultAdapter($db);
		Zend_Registry::set('db', $db);
	}
}